import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: atp
 * Date: 2022-10-12
 * Time: 17:51
 */
public class Test {

    public static int bianarySearch(int[] array,int key) {
        int left = 0;
        int right = array.length - 1 ;
        while (left <= right) {
            int mid = (left + right) >>> 1;
            if(array[mid] < key) {
                left = mid + 1;
            } else if(array[mid] > key) {
                right = mid - 1;
            } else {
                return mid;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] array = {1,3,55,4,20,7,9,16,44,66};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
        int index = bianarySearch(array,5);
        System.out.println(index);
    }

}
